package com.xja.service.impl;/**
 * @className: DataServiceImpl
 * @description: TODO 类描述
 * @author: wkx
 * @date: 2022/4/18
 **/

import com.xja.mapper.DataMapper;
import com.xja.pojo.ArticleData;
import com.xja.pojo.CommentData;
import com.xja.pojo.MoneyData;
import com.xja.pojo.UserData;
import com.xja.service.DataService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName : DataServiceImpl  //类名

 * @Author : Lenovo //作者
 * @Date: 2022/4/18  16:20
 */
@Service
public class DataServiceImpl implements DataService {

    @Autowired
    DataMapper dataMapper;
    @Transactional(readOnly = true)
    @Override
    public List<ArticleData> getArticleData() {
        return dataMapper.getArticleData();
    }
    @Transactional(readOnly = true)
    @Override
    public List<CommentData> getCommentData() {
        return dataMapper.getCommentData();
    }
    @Transactional(readOnly = true)
    @Override
    public List<UserData> getUserData() {
        return dataMapper.getUserData();
    }
    @Transactional(readOnly = true)
    @Override
    public List<MoneyData> getMoneyData() {
        List<MoneyData> data = new ArrayList<>();
        List<String> timeData = dataMapper.getTimeData();
        List<Integer> courseMoneyData = dataMapper.getCourseMoneyData();
        List<Integer> userMoneyData = dataMapper.getUserMoneyData();
        System.out.println(timeData);
        System.out.println(courseMoneyData);
        System.out.println(userMoneyData);
        if (timeData.size()!=0) {
            for (int i = 0; i < timeData.size(); i++) {

                MoneyData moneyData = new MoneyData(timeData.get(i), userMoneyData.get(i), courseMoneyData.get(i), courseMoneyData.get(i) - userMoneyData.get(i));

                data.add(moneyData);
            }
        }
        return data;

    }
}
